{% extends "base.html.twig" %}

{% import "components/new_version.macro.html.twig" as nv %}
{% import "components/search.macro.html.twig" as search %}
{% import "vars.macro.twig" as vars %}

{% block item_search %}
    {% if is_granted('@parts.read') %}
        {{ search.search_form("standalone") }}
    {% endif %}
{% endblock %}

{% block item_banner %}
    <div class="rounded p-4 bg-body-secondary">
        <h1 class="display-3">{{ vars.partdb_title() }}</h1>
        {% if settings_instance('customization').showVersionOnHomepage %}
            <h4>
                {% trans %}version.caption{% endtrans %}: {{ shivas_app_version }}
                {% if git_branch is not empty or git_commit is not empty %}
                    ({{ git_branch ?? '' }}/{{ git_commit ?? '' }})
                {% endif %}
            </h4>
        {% endif %}
        {% if banner is not empty %}
            <hr>
            <div class="latex" data-controller="common--latex">
                <h5>{{ banner | format_markdown }}</h5>
            </div>
        {% endif %}
    </div>
{% endblock %}

{% block item_first_steps %}
    {% if show_first_steps %}
        <div class="card border-info">
            <div class="card-header bg-info ">
                <h4><i class="fa fa-circle-play fa-fw " aria-hidden="true"></i> {% trans %}homepage.first_steps.title{% endtrans %}</h4>
            </div>
            <div class="card-body">
                <div>{% trans with {"%url%": "https://docs.part-db.de/usage/getting_started.html"} %}homepage.first_steps.introduction{% endtrans %}</div>
                <ul>
                    <li><a href="{{ path("category_new") }}">{{ 'category.labelp'|trans }}</a></li>
                    <li><a href="{{ path("store_location_new") }}">{{ 'storelocation.labelp'|trans }}</a></li>
                    <li><a href="{{ path("footprint_new") }}">{{ 'footprint.labelp'|trans }}</a></li>
                    <li><a href="{{ path("supplier_new") }}">{{ 'supplier.labelp'|trans }}</a></li>
                    <li><a href="{{ path("manufacturer_new") }}">{{ 'manufacturer.labelp'|trans }}</a></li>
                </ul>
                <div>{% trans with {"%url%": path('part_new')} %}homepage.first_steps.create_part{% endtrans %}</div>
                <div class="text-muted">{% trans %}homepage.first_steps.hide_hint{% endtrans %}</div>
            </div>
        </div>
    {% endif %}
{% endblock %}

{% block item_license %}
    <div class="card border-primary">
        <div class="card-header bg-primary text-white">
            <h4><i class="fa fa-book fa-fw" aria-hidden="true"></i> {% trans %}homepage.license{% endtrans %}</h4>
        </div>
        <div class="card-body">
            <p>Part-DB, Copyright &copy; 2019 - {{ "now" | date("Y") }} of <strong>
                    <a class="link-external" rel="noopener" target="_blank" href="https://github.com/jbtronics/">Jan Böhmer</a>
                </strong>. <br> Part-DB is published under the <strong>GNU Affero General Public License v3.0 (or later)</strong>, so it comes with <strong>ABSOLUTELY NO WARRANTY</strong>.
                This is free software, and you are welcome to redistribute it under certain conditions.
                Click <a href="https://raw.githubusercontent.com/Part-DB/Part-DB-server/master/LICENSE" class="link-external" rel="noopener" target="_blank">here</a> for details.<br>
            </p>
            <strong><i class="fab fa-github fa-fw"></i> {% trans %}homepage.github.caption{% endtrans %}:</strong> {% trans with {'%href%': 'https://github.com/Part-DB/Part-DB-server'}%}homepage.github.text{% endtrans %}<br>
            <strong><i class="fas fa-question fa-fw"></i> {% trans %}homepage.help.caption{% endtrans %}:</strong> {% trans with {'%href%': 'https://docs.part-db.de/'}%}homepage.help.text{% endtrans %}<br>
            <strong><i class="fas fa-comments fa-fw"></i> {% trans %}homepage.forum.caption{% endtrans %}:</strong> {% trans with {'%href%': 'https://github.com/Part-DB/Part-DB-server/discussions'}%}homepage.forum.text{% endtrans %}<br>
        </div>
    </div>
{% endblock %}

{% block item_last_activity %}
    {% if datatable is not null %}
        <div class="card">
            <div class="card-header"><i class="fas fa-fw fa-history"></i> {% trans %}homepage.last_activity{% endtrans %}</div>
            <div class="card-body">
                {% import "components/history_log_macros.html.twig" as log %}
                {{ log.last_activity_component(datatable) }}
            </div>
        </div>
    {% endif %}
{% endblock %}

{% block content %}

    {% if is_granted('@system.show_updates') %}
        {{ nv.new_version_alert(new_version_available, new_version, new_version_url) }}
    {% endif %}

    {% for item in settings_instance('customization').homepageitems %}
        {% if block('item_' ~ item.value) is defined %}
            {{ block('item_' ~ item.value) }}
            <div class="mb-2"></div>
        {% else %}
            <div class="alert alert-warning mt-3" role="alert">
                Alert: The homepage item "{{ item.value }}" is not defined!
            </div>
        {% endif %}
    {% endfor %}

{% endblock %}
